<template>
  <div class="enterprise-fix-test">
    <h2>企业信息页面修复测试</h2>
    
    <div class="test-sections">
      <div class="test-section">
        <h3>1. Cookie状态检查</h3>
        <p>JavaInfo Cookie: {{ javaInfoStatus }}</p>
        <button @click="checkCookie">检查Cookie状态</button>
        <button @click="setMockCookie">设置模拟Cookie</button>
      </div>
      
      <div class="test-section">
        <h3>2. 模拟数据测试</h3>
        <button @click="testMockData">测试模拟数据</button>
        <div v-if="mockDataResult" class="result">
          <h4>模拟企业数据：</h4>
          <pre>{{ JSON.stringify(mockDataResult, null, 2) }}</pre>
        </div>
      </div>
      
      <div class="test-section">
        <h3>3. 页面链接测试</h3>
        <a href="/account/companyInfo" target="_blank" class="test-link">
          打开企业信息页面
        </a>
      </div>
      
      <div class="test-section">
        <h3>4. 错误处理测试</h3>
        <button @click="testErrorHandling">测试错误处理</button>
        <div v-if="errorTestResult" class="result">
          <p>{{ errorTestResult }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Cookies from 'js-cookie'
import { setMockCookie, getMockEnterpriseData, getMockUserData } from '@/utils/mockData'

export default {
  name: 'EnterpriseFixTest',
  data() {
    return {
      javaInfoStatus: '未检查',
      mockDataResult: null,
      errorTestResult: null
    }
  },
  methods: {
    checkCookie() {
      const javaInfo = Cookies.get('JavaInfo')
      if (javaInfo) {
        try {
          const parsed = JSON.parse(javaInfo)
          this.javaInfoStatus = `存在: ${JSON.stringify(parsed, null, 2)}`
        } catch (e) {
          this.javaInfoStatus = `存在但格式错误: ${javaInfo}`
        }
      } else {
        this.javaInfoStatus = '不存在'
      }
    },
    
    setMockCookie() {
      setMockCookie()
      this.checkCookie()
      this.$message.success('模拟Cookie已设置')
    },
    
    testMockData() {
      this.mockDataResult = {
        enterprise: getMockEnterpriseData(),
        user: getMockUserData()
      }
    },
    
    testErrorHandling() {
      try {
        // 模拟各种错误情况
        const invalidJson = 'invalid json'
        JSON.parse(invalidJson)
      } catch (e) {
        this.errorTestResult = `错误处理正常: ${e.message}`
      }
    }
  },
  
  mounted() {
    this.checkCookie()
  }
}
</script>

<style scoped>
.enterprise-fix-test {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.test-sections {
  display: grid;
  gap: 20px;
}

.test-section {
  padding: 20px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background: #f9f9f9;
}

.test-section h3 {
  margin-top: 0;
  color: #333;
}

.test-section button {
  background: #409eff;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  margin: 5px;
}

.test-section button:hover {
  background: #66b1ff;
}

.test-link {
  display: inline-block;
  background: #67c23a;
  color: white;
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 4px;
  margin: 5px;
}

.test-link:hover {
  background: #85ce61;
}

.result {
  margin-top: 15px;
  padding: 15px;
  background: white;
  border-radius: 4px;
  border: 1px solid #ddd;
}

.result pre {
  margin: 0;
  font-size: 12px;
  color: #333;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 200px;
  overflow-y: auto;
}
</style>
